<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .a {
            width: 100%;
            height: auto;
            position: relative;
        }

        #main {
            width: 800px;
            height: 800px;
            margin: auto;
            border: 1px solid violet;
        }
    </style>
</head>

<body>
    <div class="a">
        <div id="main"></div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/echarts@5.5.1/dist/echarts.min.js"></script>
    <script type="text/javascript">
        var aa = echarts.init(document.getElementById('main'))

        // var chartDom = document.getElementById('main');
        // var myChart = echarts.init(chartDom);
        function fc() {


            var xhr = new XMLHttpRequest()
            xhr.open('get', 'https://liu.zzgoodqc.cn/goodsx/goodslist')
            xhr.send()
            xhr.responseType = 'json'
            xhr.onload = () => {
                var a = []
                var b = []
                xhr.response.data.forEach(item => {
                    a.push(item.goods_name)
                    b.push(item.sold)
                });
            

            option = {
                title: {
                    text: 'Referer of a Website',
                    subtext: 'Fake Data',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: 'Access From',
                        type: 'pie',
                        radius: '50%',
                        data: [
                            { value: b[0], name: a[0] },
                            { value: b[1], name: a[1] },
                            { value: b[2], name: a[2] },
                            { value: b[3], name: a[3] },
                            { value: b[4], name: a[4] }
                        ],
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };

            aa.setOption(option);
        }
            xhr.onerror = (e) => {
                console.log(e);

            }
        }

        fc()
    </script>
</body>

</html>